package com.ruoyi.web.controller.ccc3gc;

import com.ccc3gc.mysystem.VO.OrderVO;
import com.ccc3gc.mysystem.VO.ReceiveOrderVO;
import com.ccc3gc.mysystem.VO.SearchParamVO;
import com.ccc3gc.mysystem.bean.Order;
import com.ccc3gc.mysystem.bean.ReceiveOrder;
import com.ccc3gc.mysystem.service.OrderService;
import com.ccc3gc.mysystem.service.ReceiveOrderService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/receiveOrder")
public class ReceiveOrderController {
   @Autowired
    public ReceiveOrderService receiveOrderService;
    @Autowired
    public OrderService orderService;
    //添加接单
    @PostMapping("/add")
    public AjaxResult addDeliveryOrder(@RequestBody ReceiveOrder receiveOrder){
        System.out.println(receiveOrder);
        int rows = receiveOrderService.insertReceiveOrder(receiveOrder);
        if(rows>0){
            Integer orderId = receiveOrder.getOrderId();
            OrderVO orderVO = orderService.selectOrderByOrderId(orderId);
            Order order= new Order();
            order.setStateId( orderVO.getStateId()+1);
            order.setOrderId(orderId);
            orderService.updateOrder(order);
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
    //查询用户端，用户订单待取件列表，以及配送员接单列表，详情
    @PostMapping("/receiveList")
    public AjaxResult selectReceiveOrder(@RequestBody SearchParamVO searchParamVO){
        System.out.println(searchParamVO);
        List<ReceiveOrderVO> receiveOrderVOS = orderService.selectReceiveOrder(searchParamVO);
        return AjaxResult.success(receiveOrderVOS);
    }
}
